//
//  LYLSearchAuthorCell.m
//  ONE
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 GroupNine. All rights reserved.
//

#import "LYLSearchAuthorCell.h"

@interface LYLSearchAuthorCell ()
/** 头像 */
@property (strong, nonatomic) UIImageView *headerImageView;
/** 作者名 */
@property (strong, nonatomic) UILabel *usernameLabel;
/** 简介 */
@property (strong, nonatomic) UILabel *descLabel;

@end

@implementation LYLSearchAuthorCell

+ (CGFloat)cellHeight {
    return 64;
}

#pragma mark - View Lifecycle

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        _headerImageView = [UIImageView new];
        _headerImageView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_headerImageView];
        [_headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.equalTo(@48);
            make.centerY.equalTo(self.contentView);
            make.left.equalTo(self.contentView).offset(8);
        }];
        _headerImageView.layer.cornerRadius = 24;
        _headerImageView.layer.masksToBounds = YES;
        
        _usernameLabel = [UILabel new];
        _usernameLabel.textColor = LYLLightBlackTextColor;
        _usernameLabel.font = FontWithSize(13);
        [self.contentView addSubview:_usernameLabel];
        [_usernameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_headerImageView).offset(2);
            make.left.equalTo(_headerImageView.mas_right).offset(8);
            make.right.equalTo(self.contentView);
        }];
        
        _descLabel = [UILabel new];
        _descLabel.textColor = LYLAppThemeColor;
        _descLabel.font = FontWithSize(12);
        [self.contentView addSubview:_descLabel];
        [_descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(_usernameLabel);
            make.bottom.equalTo(_headerImageView).offset(-4);
        }];
    }
    
    return self;
}

//- (void)prepareForReuse {
//    [super prepareForReuse];
//    _headerImageView.image = nil;
//}

- (void)setModel:(LYLAuthorItemModel *)model
{
    if (_model != model) {
        _model = model;
        [_headerImageView sd_setImageWithURL:[NSURL URLWithString:model.web_url] placeholderImage:[UIImage imageNamed:@"home_cover_placeholder"] options:SDWebImageRetryFailed];
        _usernameLabel.text = model.user_name;
        _descLabel.text = model.desc;
    }
}


@end
